<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>信审后续回访记录</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
		<form id="formSet1">
			<div class="fieldset1 tabel_col clearFix">
				<div class="fieldBox col_100">
					<div class="sqPanel">
		                <div class="sqPanel_head inL">
		                    <div class="btnsBox inLC">
		                        <span id="addBtn" class="sq-button sq-button-round" onclick="addRecord();">添加</span>
		                        <span id="delBtn" class="sq-button sq-button-round" onclick="delRecord();">删除</span>
		                    </div>
		                    <span>后续回访记录</span>
		                </div>
		                <div class="sqPanel_body">
		                    <div id="ligergrid_flowReturn" class="sq-grid"></div>
		                </div>
					</div>
				</div>
			</div>
			<div class="btnsBox">
                <input type="hidden" id="visitId" name="visitId" value="${visitId }">
            </div>
		</form>
	</div>
</div>

<script type="text/javascript">
var _visitId = '${visitId}';//回访信息ID
var _cstMgrId = '${cstMgrId}';//客户经理ID
var _cstMgrNm = '${cstMgrNm}';//客户经理名称
var _userId = '${userId}';//当前登录人ID
var _userNm = '${userNm}';//当前登录人名称
var flowReturnGrid;
var isDetail = '${isDetail}';

//信审员
var auditUsrKVListJSON = [];
<c:if test="${not empty auditUsrKVListJSON}"> auditUsrKVListJSON = ${auditUsrKVListJSON}; </c:if>
$(function(){
	$('#formSet1').ligerForm({
        validate : true
	});
	if(isDetail==1){
		$("#saveBtn1").remove();
		$("#addBtn").remove();
		$("#delBtn").remove();
	}
	
	//回访人员类型
	var personnelTypeCdListJSON = [];
    <c:if test="${not empty personnelTypeCdListJSON}"> personnelTypeCdListJSON = ${personnelTypeCdListJSON}; </c:if>
    
	flowReturnGrid = $("#ligergrid_flowReturn").ligerGrid({
        url: '<%=path%>/audit/audVisitRecord/initList.do',
        method: 'get',
        parms:{
        	visitId:_visitId,
        	visitTypeCd:AuditConstant.AUD_VISIT_TYP_CD_FLOW
        },
        columns: [
            {display: '回访人员类型', name: 'personnelTypeCd', width: 100,
                editor: {
                    type: 'select',
                    data: personnelTypeCdListJSON,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'personnelTypeCd',
                textField: 'personnelTypeCdNm',
                render: function (item) {
                    return item.personnelTypeCdNm;
                }
            },
            {display: '回访人员姓名', name: 'personnelName', width: 100, editor: {type: 'text'} },
            {display: '客户经理ID', name: 'accountManagerId', width: 0, editor: {readonly: true},hide:true },
            {display: '客户经理', name: 'accountManagerNm', width: 100, editor: {readonly: true} },
            /* {display: '信审员ID', name: 'auditorId', width: 0, editor: {readonly: true},hide:true },
            {display: '信审员', name: 'auditorNm', width: 100, editor: {readonly: true} }, */
            {display: '信审员', name: 'auditorId', width: 100,
			    editor: {
			        type: 'combobox',
			        data: auditUsrKVListJSON,
			        initData: auditUsrKVListJSON,
			        valueField: 'key',
			        textField: 'value',
			        autocomplete: function (e){
			            filter_autoComboboxData(e.key, this);
			            e.show();
			        },
			        onChangeValue: function (value) {
			            if (this.findValueByText(value) == "") {//清除输入值
			                this.setValue("");
			            }
			        },
			    },
			    valueField: 'auditorId',
			    textField: 'auditorNm',
			    render: function (item) {
			        return item.auditorNm;
			    }
			},
            {width: 150,
                display: '回访时间', name: 'visitTm',
                editor: {type: 'date'},
                render: function (rowdata, index, value) {
                    var result = '';
                    if (StringUtils.isEmpty(value)) return result;
                    var date = new Date(value);
                    result = date.Format('yyyy-MM-dd');
                    return result;
                }
            },
            {display: '回访电话', name: 'phone', width: 100, editor: {type: 'text'} },
            {display: '回访内容', name: 'content', width: 100, editor: {type: 'text'} },
        ],
        onBeforeSubmitEdit: function (e) {
        	
        },
        onBeforeEdit: function (e) {
        	if(isDetail==1){
        		e.column.editor.readonly=true;
        	}
        },
        usePager: false,
        root: 'rows',
        record: 'total',
        hideLoadButton: true,
        width: '100%',
        height: 300,
        heightDiff: -2,
        enabledEdit: true,
        isScroll: false,
        checkbox: true,
        rownumbers: true,
        allowUnSelectRow: true,
        alternatingRow: false,
        enabledSort:false
    });
	SET_popupIframeHeight();
})
//定义父级调用事件
frameElement.dialog.onOk = function () {
     save();
}
frameElement.dialog.onCancel = function () {
     frameElement.dialog.close();
}
function save(){
	var form = liger.get("formSet1");
    if (!form.valid()) {
    	$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
        return false;
    }
    var data = form.getData();
    data["visitId"] = _visitId;
    data["visitTypeCd"] = AuditConstant.AUD_VISIT_TYP_CD_FLOW; //回访类型-后续回访
    data["VisitRecordDetailJSON"] = JSON.stringify(flowReturnGrid.getData());//后续回访记录信息
    
    var url = '<%=path%>/audit/audVisitRecord/add.do';
    var wait_dialog;
    $.ajax({
		type: 'post',
		dataType:'json',
		data:data,
		url: url,
		beforeSend: function(){
	          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	     },
		success:function(msg){
			 wait_dialog.close();
			 if(msg.success == 1){
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
				 frameElement.dialog.close();
			 }else{
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
			 }
			 flowReturnGrid.reload();
		}
	});
}
function addRecord(){
	flowReturnGrid.addRow({
		personnelTypeCd: '',
		personnelName: '',
		accountManagerId: _cstMgrId,
		accountManagerNm: _cstMgrNm,
		auditorId:'',
		/* auditorId: _userId,
		auditorNm: _userNm, */
		visitTm: '',
		phone: '',
		content: ''
    });
}
function delRecord(){
	var selectedRows = flowReturnGrid.getSelectedRows();
	if(selectedRows.length == 0){
		$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warring"});
		return;
	}
	top.$.ligerDialog.confirm("确认删除选中项吗?", function (flag) {
		if(!flag){
			return;
		}else{
			var _ids = [];
			for (var i = 0; i < selectedRows.length; i++) {
				if(!selectedRows[i].id){
					flowReturnGrid.deleteRow(selectedRows[i]); 
				}else{
					_ids.push(selectedRows[i].id);
				}
			}
			if(_ids.length==0)return;
			//请求后台批量删除
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/audit/audVisitRecord/removeByIds.do',
				beforeSend: function(){
			          wait_dialog=top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 flowReturnGrid.reload();
					 }else{
						 top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		}
	});
}
</script>

</body>
</html>
